<?php

class Login extends Controller {

    function Login()
    {
        parent::Controller();
    }


    function index()
    {
        // jangan login ulang
        if($this->session->userdata('id_admin'))
            redirect('admin/home');


        if($this->input->post('submit'))
        {
            $userdata = array();
            $username = $this->input->post('admin_username');
            $password = md5($this->input->post('admin_password'));
            $this->db->where('username', $username);
            $this->db->where('password', $password);
            $q = $this->db->get('tb_admin');

            if($q->num_rows() > 0)
            {
                $userdata = $q->row_array();
                $this->session->set_userdata($userdata);
                redirect('admin/home');
            }
            else
            {
                $data['error'] = "Username atau password salah";
            }

        }

        $data['template_konten'] = 'admin/admin_login';

        $this->load->vars($data);
        $this->load->view('admin/admin_login');
    }

    function out()
    {

        $this->session->sess_destroy();

        $data = array();
        $data['template_konten'] = 'admin/admin_logout';

        $this->load->vars($data);
        $this->load->view('admin/template');
    }


}
